@using System.Text.RegularExpressions
@using ZKEACMS.SectionWidget.Models
@model SectionContent
@{
    Layout = Layouts.ClientPopUp;
    SectionContentVideo video = Model as SectionContentVideo;
    if (video == null)
    {
        return;
    }
    ViewBag.Title = video.VideoTitle;
    Style.Reqiured("Section").AtFoot();
}

<div class="pop-video">
    @if (video.Url.IsNotNullAndWhiteSpace())
    {
        <video id="video-player" controls="controls"
               autoplay="autoplay"
               playsinline
               name="media"
               src="@Url.Content(video.Url)"
               style="width:@(video.Width.HasValue?video.Width+"px":"auto");height:@(video.Height.HasValue?video.Height+"px":"auto")">
            Your brower does not support playing video.
        </video>
    }
    else if (video.Code.IsNotNullAndWhiteSpace())
    {
        video.Code = Regex.Replace(video.Code, @"("")?width("")?=("")?(\d+)("")?", "width=\"" + (video.Width ?? 798) + "\"");
        video.Code = Regex.Replace(video.Code, @"("")?width("")?:("")?(\d+)("")?", "width:" + (video.Width ?? 798));

        video.Code = Regex.Replace(video.Code, @"("")?height("")?=("")?(\d+)("")?", "height=" + (video.Height ?? 500));
        video.Code = Regex.Replace(video.Code, @"("")?height("")?:("")?(\d+)("")?", "height:" + (video.Height ?? 500));

        @Html.Raw(video.Code)
    }
</div>
@using (Script.AtFoot())
{
    <script type="text/javascript">
        $(function () {
            document.getElementById("video-player").play();
        });
    </script>
}